local fn = vim.fn

local ends_with = function(str, ending)
  return ending == "" or str:sub(- #ending) == ending
end

local M = {}

M.setup = function()
  local config_dir = fn.stdpath("config").."/lua/conf"
  local exloads = {
    init = true,
  }
  for _, fname in pairs(fn.readdir(config_dir)) do
    if ends_with(fname, ".lua") then 
      local cut_suffix_fname = fname:sub(1, #fname - #".lua")
      if exloads[cut_suffix_fname] == nil then
        local file = "conf."..cut_suffix_fname
        local status_ok, _ = pcall(require, file)
        if not status_ok then
          vim.notify("Failed loading "..fname, vim.log.levels.ERROR)
        end
      end
    end
  end
end

M.setup()